package org.punkgrok.flightrecorder;

import java.util.Arrays;

/**
 * User: Roman Florian Zabicki III
 * Date: May 25, 2009
 * Time: 9:41:04 PM
 */
public class MethodInvocation {
	private String methodName;
	private Object[] args;
	private Object returnValue;

	public MethodInvocation(String methodName, Object[] args, Object returnValue) {
		this.methodName = methodName;
		this.args = args;
		this.returnValue = returnValue;
	}

	public String getMethodName() {
		return methodName;
	}

	public Object[] getArgs() {
		return args;
	}

	public Object getReturnValue() {
		return returnValue;
	}

	@Override
	public String toString() {
		return methodName + "(" + (args == null ? "" : Arrays.toString(args)) + ")=" + returnValue;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;

		MethodInvocation that = (MethodInvocation) o;

		// Probably incorrect - comparing Object[] arrays with Arrays.equals
		if (!Arrays.equals(args, that.args)) return false;
		if (methodName != null ? !methodName.equals(that.methodName) : that.methodName != null) return false;
		if (returnValue != null ? !returnValue.equals(that.returnValue) : that.returnValue != null) return false;

		return true;
	}

	@Override
	public int hashCode() {
		int result = methodName != null ? methodName.hashCode() : 0;
		result = 31 * result + (args != null ? Arrays.hashCode(args) : 0);
		result = 31 * result + (returnValue != null ? returnValue.hashCode() : 0);
		return result;
	}
}
